<?php
/**
 * UCenter 应用程序开发 Example
 *
 * UCenter 简易应用程序，应用程序无数据库
 * 使用到的接口函数：
 * uc_authcode()	可选，借用用户中心的函数加解密 Cookie
 * uc_pm_checknew()	可选，用于全局判断是否有新短消息，返回 $newpm 变量
 */
define('RENT_ROOT', dirname(str_replace('\\', '/', __FILE__)));
include_once(dirname(RENT_ROOT).'/common.php');
checkclose();
date_Default_TimeZone_set("PRC");

include './config.inc.php';
include './uc_client/client.php';

/**
 * 获取当前用户的 UID 和 用户名
 * Cookie 解密直接用 uc_authcode 函数，用户使用自己的函数
 */
if(!empty($_COOKIE['examples_auth'])) {
	list($Example_uid, $Example_username) = explode("\t", uc_authcode($_COOKIE['examples_auth'], 'DECODE'));
} else {
	$Example_uid = $Example_username = '';
}

/*if(!$Example_username) {
	//用户未登录
	echo '<a href="'.$_SERVER['PHP_SELF'].'?example=login">登录</a> ';
	echo '<a href="'.$_SERVER['PHP_SELF'].'?example=register">注册</a> ';
} else {
	//用户已登录
	echo '<script src="ucexample.js"></script><div id="append_parent"></div>';
	echo $Example_username.' <a href="'.$_SERVER['PHP_SELF'].'?example=logout">退出</a> ';
	echo ' <a href="'.$_SERVER['PHP_SELF'].'?example=pmlist">短消息列表</a> ';
	echo $newpm ? '<font color="red">New!('.$newpm.')</font> ' : NULL;
	echo '<a href="###" onclick="pmwin(\'open\')">进入短消息中心</a> ';
	echo ' <a href="'.$_SERVER['PHP_SELF'].'?example=friend">好友</a> ';
	echo ' <a href="'.$_SERVER['PHP_SELF'].'?example=avatar">头像</a> ';
}*/

//房产信息-》租房-》district-》area
$step = $_GET['s'];
$aid = $_GET['aid'];//最近的id,
$cid = $_GET['cid'];//类别，如果类别id没有则设为0
$city_id = 7;
if ($step == 2)//目前只从2开始
{
	$nav = array(
		1=>array(
			'name'=>'房产信息',
			'href'=>'',
			'active'=>0,
		),
		2=>array(
			'name'=>'选择小类',
			'href'=>'',
			'active'=>1,
		),
		3=>array(
			'name'=>'选择区域',
			'href'=>'',
			'active'=>0,
		),
		4=>array(
			'name'=>'选择商圈',
			'href'=>'',
			'active'=>0,
		),
		5=>array(
			'name'=>'填写信息',
			'href'=>'',
			'active'=>0,
		),		
	);
	$data = array();
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('rent_infor_category')." WHERE acid='$aid'");
	$data = $_SGLOBAL['db']->fetch_all($query);
	$fast_nav = array();
	
	//var_dump($data);exit;
}
elseif ($step == 3)
{
	$cid = ($cid==0)?$aid:$cid;
	//已知模块，选择区
	//得到模块的详细信息
	$query1 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('rent_infor_category')." WHERE id='$cid'");
	$info_cate =$_SGLOBAL['db']->fetch_array($query1);	 
	//var_dump($info_cate);
	$nav = array(
		1=>array(
			'name'=>'房产信息',
			'href'=>'',
			'active'=>0,
		),
		2=>array(
			'name'=>$info_cate["name"],
			'href'=>'post.php?cid=0&aid=1&s=2',
			'active'=>0,
		),
		3=>array(
			'name'=>'选择区域',
			'href'=>'',
			'active'=>1,
		),
		4=>array(
			'name'=>'选择商圈',
			'href'=>'',
			'active'=>0,
		),
		5=>array(
			'name'=>'填写信息',
			'href'=>'',
			'active'=>0,
		),		
	);
	//得到所有区的信息
	$query2 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('rent_district')." WHERE cid='$city_id'");
	$data =$_SGLOBAL['db']->fetch_all($query2);
	$fast_nav = array(
		0=>array(
			'name'=>'重新选择小类',
			'href'=>'post.php?aid='.$info_cate["id"].'&s=2',
		),
		1=>array(
			'name'=>'跳过，将信息发布到全北京',
			'href'=>'',
		),
	);
}
elseif ($step == 4)
{
	//得到应用的详细信息
	$query0 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('rent_infor_category')." WHERE id='$cid'");
	$info_cate =$_SGLOBAL['db']->fetch_array($query0);	 
	//已知区，选择商圈
	//得到模块的详细信息
	$query1 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('rent_district')." WHERE id='$aid'");
	$info_dist =$_SGLOBAL['db']->fetch_array($query1);	 
	$nav = array(
		1=>array(
			'name'=>'房产信息',
			'href'=>'',
			'active'=>0,
		),
		2=>array(
			'name'=>$info_cate["name"],
			'href'=>'post.php?cid=0&aid=1&s=2',
			'active'=>0,
		),
		3=>array(
			'name'=>$info_dist["name"],
			'href'=>'post.php?cid='.$info_cate["id"].'&aid='.$info_dist["id"].'&s=3',
			'active'=>0,
		),
		4=>array(
			'name'=>'选择商圈',
			'href'=>'',
			'active'=>1,
		),
		5=>array(
			'name'=>'填写信息',
			'href'=>'',
			'active'=>0,
		),		
	);
	//得到所有区的信息
	$query2 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('rent_area')." WHERE did='$aid'");
	$data =$_SGLOBAL['db']->fetch_all($query2);
	$fast_nav = array(
		0=>array(
			'name'=>'重新选择区域',
			'href'=>'post.php?cid='.$info_cate["id"].'&aid='.$info_dist["id"].'&s=3',
		),
		1=>array(
			'name'=>'跳过，将信息发布到全北京',
			'href'=>'',
		),
	);
}
else 
{
	//得到应用的详细信息
	$query0 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('rent_infor_category')." WHERE id='$cid'");
	$info_cate =$_SGLOBAL['db']->fetch_array($query0);	 
	//已知区和商圈信息
	//得到模块的详细信息
	$query1 = $_SGLOBAL['db']->query("SELECT a.id as aid, a.name as aname, d.id as did, d.name as dname FROM ".tname('rent_area')." a ,".tname('rent_district')." d  WHERE a.did=d.id and a.id='$aid'");
	$info_area =$_SGLOBAL['db']->fetch_array($query1);
	//var_dump($info_area);exit;	 
	$nav = array(
		1=>array(
			'name'=>'房产信息',
			'href'=>'',
			'active'=>0,
		),
		2=>array(
			'name'=>$info_cate["name"],
			'href'=>'post.php?cid=0&aid=1&s=2',
			'active'=>0,
		),
		3=>array(
			'name'=>$info_area["dname"],
			'href'=>'post.php?cid='.$cid.'&aid='.$info_area["did"].'&s=3',
			'active'=>0,
		),
		4=>array(
			'name'=>$info_area["aname"],
			'href'=>'post.php?cid='.$cid.'&aid='.$info_area["aid"].'&s=4',
			'active'=>0,
		),
		5=>array(
			'name'=>'填写信息',
			'href'=>'',
			'active'=>1,
		),		
	);
	//付款方式
	$query = $_SGLOBAL['db']->query("SELECT a.id as aid, a.name as name, b.id as id, b.value as value FROM ".tname('rent_attribute')." a, ".tname('rent_attr_value')." b WHERE a.id = b.aid and a.id and a.cateid
	IN (
	SELECT id
	FROM ".tname('rent_infor_category')."
	WHERE acid =1
	)
	");
	$attr_value =$_SGLOBAL['db']->fetch_all($query);	
	//$fkfs =
	$arr = array();
	foreach ($attr_value as $val)
	{
		$arr[$val['aid']][] = $val;
	}
	//var_dump($arr);exit; 
}
$new_step = $step+1;

include_once template('rent/template/post');
?>